package net.lab1024.sa.admin.module.business.yct.yctTeeth.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.dao.TemplatelogDao;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.entity.TemplatelogEntity;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.TemplatelogAddForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.TemplatelogQueryForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.form.TemplatelogUpdateForm;
import net.lab1024.sa.admin.module.business.yct.yctTeeth.domain.vo.TemplatelogVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 模板消息发送日志 Service
 *
 * @Author zhangben
 * @Date 2024-12-26 09:36:53
 * @Copyright 20241226
 */

@Service
public class TemplatelogService {

    @Resource
    private TemplatelogDao templatelogDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<TemplatelogVO> queryPage(TemplatelogQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<TemplatelogVO> list = templatelogDao.queryPage(page, queryForm);
        PageResult<TemplatelogVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(TemplatelogAddForm addForm) {
        TemplatelogEntity templatelogEntity = SmartBeanUtil.copy(addForm, TemplatelogEntity.class);
        templatelogDao.insert(templatelogEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(TemplatelogUpdateForm updateForm) {
        TemplatelogEntity templatelogEntity = SmartBeanUtil.copy(updateForm, TemplatelogEntity.class);
        templatelogDao.updateById(templatelogEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        templatelogDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer massageId) {
        if (null == massageId){
            return ResponseDTO.ok();
        }

        templatelogDao.deleteById(massageId);
        return ResponseDTO.ok();
    }
}
